package net.alteiar.dungeon.generator;

import java.awt.Color;
import java.awt.Polygon;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import net.alteiar.Array2D;

public class MapBuilder {
	private static Random RANDOM = new Random();

	private final Array2D map2D;

	private final int minSizeRoom;
	private final int maxSizeRoom;

	private final List<Polygon> lst;

	public MapBuilder() {
		map2D = new Array2D(300, 300);

		map2D.fill(Color.WHITE.getRGB());

		minSizeRoom = 5;
		maxSizeRoom = 50;

		lst = new ArrayList<>();
		for (int i = 0; i < 40; ++i) {
			lst.add(buildRoom());
		}
	}

	private Polygon buildRoom() {
		int width = RANDOM.nextInt(maxSizeRoom - minSizeRoom) + minSizeRoom;
		int height = RANDOM.nextInt(maxSizeRoom - minSizeRoom) + minSizeRoom;

		int x = RANDOM.nextInt(300 - width);
		int y = RANDOM.nextInt(300 - height);

		return new Polygon(new int[] { x, x + width, x, x + width }, new int[] {
				y, y, y + height, y + height }, 4);
	}

	public Array2D buildMap() {
		return map2D;
	}
}
